<?php
/**
  @author:猪也知道
  @describe:
  @date:2010/10/06
 * */
try {
  $dsn = "mysql:host=localhost;dbname=sunny";
  $db = new PDO($dsn, 'root', '123');
  $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  $db->exec("SET NAMES 'UTF8'");
  $sql = "INSERT INTO tc0_log(name,content,ip,datetime) values('admin','插入一条记录','{$_SERVER['REMOTE_ADDR']}',now())";
  $db->exec($sql);
  echo 'successed!','<br />';
  $insert=$db->prepare("INSERT INTO tc0_log(name,content,ip,datetime) values(?,?,?,now())");
  $insert->execute(array('admin','插入一条记录1111',"{$_SERVER['REMOTE_ADDR']}"));
  $insert->execute(array('admin','插入一条记录2222',"{$_SERVER['REMOTE_ADDR']}"));
  $insert->execute(array('admin','插入一条记录2222',"{$_SERVER['REMOTE_ADDR']}"));
//  $insert->execute(array('admin','插入一条记录2222',"{$_SERVER['REMOTE_ADDR']}",8,9));

  echo 'successed!','<br />';
  $sql="select name,content,ip,datetime from tc0_log";
  $query = $db->prepare($sql);
  $query->execute();
  var_dump($query->fetchAll(PDO::FETCH_ASSOC));

$db->beginTransaction();
$db->exec("INSERT INTO tc0_log(name,content,ip,datetime) values('admin','bb','{$_SERVER['REMOTE_ADDR']}',now())");
$db-> exec ("insert into staff (id, first, last) values(23, 'Joe', 'Bloggs')" );
$db->commit();
//$db->commit();
  echo '<hr>';
 
} catch (PDOExceptionn $err) {
   echo $err->getMessage();

}



?>
